package com.tanhua.server.peachblossom.controller;

import com.tanhua.server.peachblossom.service.PeachBlossomService;
import com.tanhua.server.peachblossom.vo.PeachBlossomResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping( "peachblossom" )
public class PeachBlossomController {
    @Autowired
    private PeachBlossomService peachBlossomService;

    @GetMapping
    public ResponseEntity<PeachBlossomResult> getPeachBlossom(  ){

        PeachBlossomResult peachBlossomResult = this.peachBlossomService.getPeachBlossom();
        if( peachBlossomResult != null ){
            //peachBlossomResult 不为空!
            return ResponseEntity.ok(peachBlossomResult);
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @PostMapping
    public ResponseEntity<Void> savePeachBlossom( @RequestParam(value = "soundFile", required = false) MultipartFile soundFile) {
        try {
            Boolean saveSound = peachBlossomService.saveSound(soundFile);
            if (saveSound) {

                return ResponseEntity.ok(null);
            }
            else return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        } catch (Exception e) {
            e.printStackTrace();
        }


        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
